package com.techsoul.module.tms.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.log.annotation.Log;
import com.techsoul.common.log.enums.OperationTypeEnum;
import com.techsoul.module.pms.enmus.DriverTypeEnum;
import com.techsoul.module.tms.pojo.param.*;
import com.techsoul.module.tms.pojo.vo.CarrierVo;
import com.techsoul.module.tms.pojo.vo.DriverVo;
import com.techsoul.module.tms.service.ICarrierService;
import com.techsoul.module.tms.service.IExpressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * 前端控制器
 *
 * @author zhaowei
 * @since 2021-06-02
 */
@Api(tags = "货主相关")
@RestController
@RequestMapping("/tms/carrier")
public class CarrierController {
    @Autowired
    private ICarrierService service;

    @Autowired
    private IExpressService iExpressService;
    @Autowired
    private Result result;
    @PostMapping
    public String insert(@RequestBody CarrierSaveParam params) {
        return service.insert(params);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable String id) {
        service.delete(id);
    }

    @PutMapping("/{id}")
    public void update(@PathVariable String id, @RequestBody CarrierSaveParam params) {
        service.update(id, params);
    }

    @GetMapping("/{id}")
    public CarrierVo findById(@PathVariable("id") String id) {
        return service.findById(id);
    }

    @PostMapping("/search")
    public List<CarrierVo> findAll(@RequestBody CarrierSearchParam params) {

        return service.findAll(params);
    }

    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result findAll(@RequestBody CarrierSearchParam params, @PathVariable Integer currentPage,
        @PathVariable Integer pageSize) {
        return result.success(this.service.findAll(params, currentPage, pageSize));
    }

    @PostMapping("/driverSearch/{currentPage}/{pageSize}")
    public Result driverSearch(@RequestBody DriverSearchParam params, @PathVariable Integer currentPage,
                               @PathVariable Integer pageSize) {
        params.setDriverType(DriverTypeEnum.self.getValue());

        return result.success(this.iExpressService.driverSearch(params, currentPage, pageSize));
    }

    @PostMapping("/driverFindAll")
    public Result driverFindAll(@RequestBody DriverSearchParam params) {
        params.setDriverType(DriverTypeEnum.self.getValue());

        return result.success(this.iExpressService.driverFindAll(params));
    }

    @PostMapping("/carrierFindAll")
    public Result carrierFindAll(@RequestBody CarrierSearchParam params) {
        return result.success(this.iExpressService.carrierFindAll(params));
    }


}
